import SoundUtil from "../../Fantasy/Util/SoundUtil";

// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class SettingJs extends cc.Component {
    @property(cc.Node)
    openMusic:cc.Node = null;
    @property(cc.Node)
    closeMusic:cc.Node = null;
    @property(cc.Node)
    openVoice:cc.Node = null;
    @property(cc.Node)
    closeVoice:cc.Node = null;
    onLoad () {
        if(ReadLocal('EffectSwitch', 'true') == 'true'){
            this.openVoice.active = true;
            this.closeVoice.active = false;
        }else{
            this.openVoice.active = false;
            this.closeVoice.active = true;
        }
        if(ReadLocal('SoundSwitch', 'true') == 'true'){
            this.openMusic.active = true;
            this.closeMusic.active = false;
        }else{
            this.openMusic.active = false;
            this.closeMusic.active = true;
        }

    }

    start () {

    }
    btnCallback(target,data){
        SoundUtil.playEffect("music/click");
        if(data == "music"){
            this.openMusic.active = this.closeMusic.active;
            this.closeMusic.active = !this.closeMusic.active;
            SoundUtil.SetMusicSwitch();
        }else if(data == "voice"){
            this.openVoice.active = !this.openVoice.active;
            this.closeVoice.active = !this.closeVoice.active;
            SoundUtil.SetEffectSwitch();
        }else if(data == "close"){
            if(this.node){
                this.node.destroy();
            }
        }
    }

    

    // update (dt) {}
}
